home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2007 June/July / Windows News Hors série Numéro 34 juin juillet 2007.iso / Rédaction / Astuces Windows XP / tailledossiers.vbs < prev    next >
Encoding:
Text File  |  2006-11-30  |  5.3 KB  |  161 lines

  1. On Error Resume Next
  2.  
  3. Const inBYTE = 1
  4. Const inKILO = 1024      ' 2^10
  5. Const inMEGA = 1048576     ' 2^20
  6. Const inGIGA = 1073741824    ' 2^30
  7. Const inTERA = 1099511627776   ' 2^40
  8. Const inPETA = 1.12589990684262E+15  ' 2^50
  9. Const inEXA = 1.15292150460685E+18  ' 2^60
  10. Const inZETTA = 1.18059162071741E+21 ' 2^70
  11. Const inYOTTA = 1.20892581961463E+24 ' 2^80
  12.  
  13.  
  14. Set objWshShell = CreateObject("WScript.Shell")
  15. strDesktop = objWshShell.SpecialFolders("Desktop")
  16. fSaveName = strDesktop & "\dossiers.htm"
  17. fCalcPath = InputBox("Quel est le chemin d'accΦs au dossier α analyser ?","Taille d'un dossier")
  18. If fCalcPath = "" Then Wscript.Quit
  19. Set objFSO = CreateObject("Scripting.FileSystemObject")
  20. Set FileTxt = objFSO.CreateTextFile(fSaveName, True)
  21. Set Folder = objFSO.GetFolder(fCalcPath)
  22.  
  23. FileTxt.WriteLine "<html><body><table border=1 cellpadding=2 cellspacing=0><th>Dossiers</th><th>Taille dossiers</th><th>Taille dossiers et sous-dossiers</th>"
  24.  
  25.  
  26. Set rootFolder = objFSO.GetFolder(Folder)
  27. For Each rootSubFolder in rootFolder.Subfolders
  28. Set colFiles = rootFolder.Files
  29.  
  30.  
  31. For Each objFile in colFiles
  32.  tSize = objFile.Size + tSize
  33. Next
  34.  
  35. tfSize = rootSubFolder.Size + tfSize
  36. Next 
  37. If tSize < inKILO Then
  38. fSize = (tSize/inBYTE)
  39. tSize = FormatNumber(fSize,,,,0) & " octets"
  40. ElseIf tSize < inMEGA Then
  41. fSize = (tSize/inKILO)
  42. tSize = FormatNumber(fSize,,,,0) & " Ko"
  43. ElseIf tSize < inGIGA Then
  44. fSize = (tSize/inMEGA)
  45. tSize = FormatNumber(fSize,,,,0) & " Mo"
  46. ElseIf tSize < inTERA Then
  47. fSize = (tSize/inGIGA)
  48. tSize = "<b style=color:#FF0000>" & FormatNumber(fSize,,,,0) & " Go</b>"
  49. End If
  50. If tfSize < inKILO Then
  51. ffSize = (tfSize/inBYTE)
  52. tfSize = FormatNumber(ffSize,,,,0) & " octets"
  53. ElseIf tfSize < inMEGA Then 
  54. ffSize = (tfSize/inKILO)
  55. tfSize = FormatNumber(ffSize,,,,0) & " Ko"
  56. ElseIf tfSize < inGIGA Then 
  57. ffSize = (tfSize/inMEGA)
  58. tfSize = FormatNumber(ffSize,,,,0) & " Mo"
  59. ElseIf tfSize < inTERA Then 
  60. ffSize = (tfSize/inGIGA)
  61. tfSize = "<b style=color:#FF0000>" & FormatNumber(ffSize,,,,0) & " Go</b>"
  62. End If 
  63. FileTxt.WriteLine "<tr bgcolor=#FFFFCC><td><a href='" & Folder.Path & "'>" & Folder.Path & "</a></td><td align=right>" & tSize & "</td><td align=right>" & tfSize & "</td></tr>"
  64. tsize = 0
  65. Set rootFolder = Nothing
  66.  
  67.  
  68. For Each SubFolder In Folder.Subfolders 
  69. Set currentFolder = objFSO.GetFolder(SubFolder)
  70. Set colFiles = currentFolder.Files
  71. '** get subfolder files
  72. For Each objFile in colFiles
  73.  tSize = objFile.Size + tSize
  74. Next
  75. If tSize < inKILO Then
  76.  fSize = (tSize/inBYTE)
  77.  tSize = FormatNumber(fSize,,,,0) & " octets"
  78. ElseIf tSize < inMEGA Then
  79.  fSize = (tSize/inKILO)
  80.  tSize = FormatNumber(fSize,,,,0) & " Ko"
  81. ElseIf tSize < inGIGA Then
  82.  fSize = (tSize/inMEGA)
  83.  tSize = FormatNumber(fSize,,,,0) & " Mo"
  84. ElseIf tSize < inTERA Then
  85.  fSize = (tSize/inGIGA)
  86.  tSize = "<b style=color:#FF0000>" & FormatNumber(fSize,,,,0) & " Go</b>"
  87. End If
  88. If (SubFolder.Size < inKILO) Then
  89.  ffSize = (SubFolder.Size/inBYTE)
  90.  tfSize = FormatNumber(ffSize,,,,0) & " octets"
  91. ElseIf (SubFolder.Size < inMEGA) Then 
  92.  ffSize = (SubFolder.Size/inKILO)
  93.  tfSize = FormatNumber(ffSize,,,,0) & " Ko"
  94. ElseIf (SubFolder.Size < inGIGA) Then 
  95.  ffSize = (SubFolder.Size/inMEGA)
  96.  tfSize = FormatNumber(ffSize,,,,0) & " Mo"
  97. ElseIf (SubFolder.Size < inTERA) Then 
  98.  ffSize = (SubFolder.Size/inGIGA)
  99.  tfSize = "<b style=color:#FF0000>" & FormatNumber(ffSize,,,,0) & " Go</b>"
  100. End If 
  101.  
  102. FileTxt.WriteLine "<tr bgcolor=#FFFFCC><td><a href='" & SubFolder.Path & "'>" & SubFolder.Path & "</a></td><td align=right>" & tSize & "</td><td align=right>" & tfSize & "</td></tr>"
  103. tsize = 0
  104. funcGetSubFolders SubFolder.Path
  105. Next
  106.  
  107.  
  108. FileTxt.WriteLine "</table></body></html>"
  109. FileTxt.Close
  110. MsgBox "Fin de l'analyse. Ouvrez le fichier " & fSaveName,64,"Taille des dossiers"
  111. Set objFSO = Nothing
  112. Set FileTxt = Nothing
  113. Set Folder = Nothing
  114. Wscript.Quit
  115.  
  116.  
  117. Sub funcGetSubFolders(sPath)
  118. Set objFldr = objFSO.GetFolder(sPath)
  119. For Each SubFolder In objFldr.SubFolders
  120. Set currentFolder = objFSO.GetFolder(SubFolder)
  121. Set colFiles = currentFolder.Files
  122.  
  123. For Each objFile in colFiles
  124.  tSize = objFile.Size + tSize
  125. Next
  126.  
  127. If tSize < inKILO Then
  128.  fSize = (tSize/inBYTE)
  129.  tSize = FormatNumber(fSize,,,,0) & " bytes"
  130. ElseIf tSize < inMEGA Then
  131.  fSize = (tSize/inKILO)
  132.  tSize = FormatNumber(fSize,,,,0) & " kb"
  133. ElseIf tSize < inGIGA Then
  134.  fSize = (tSize/inMEGA)
  135.  tSize = FormatNumber(fSize,,,,0) & " MB"
  136. ElseIf tSize < inTERA Then
  137.  fSize = (tSize/inGIGA)
  138.  tSize = "<b style=color:#FF0000>" & FormatNumber(fSize,,,,0) & " GB</b>"
  139. End If
  140.  
  141. If (SubFolder.Size < inKILO) Then
  142.  ffSize = (SubFolder.Size/inBYTE)
  143.  tfSize = FormatNumber(ffSize,,,,0) & " bytes"
  144. ElseIf (SubFolder.Size < inMEGA) Then 
  145.  ffSize = (SubFolder.Size/inKILO)
  146.  tfSize = FormatNumber(ffSize,,,,0) & " kb"
  147. ElseIf (SubFolder.Size < inGIGA) Then 
  148.  ffSize = (SubFolder.Size/inMEGA)
  149.  tfSize = FormatNumber(ffSize,,,,0) & " MB"
  150. ElseIf (SubFolder.Size < inTERA) Then 
  151.  ffSize = (SubFolder.Size/inGIGA)
  152.  tfSize = "<b style=color:#FF0000>" & FormatNumber(ffSize,,,,0) & " GB</b>"
  153. End If  
  154.  
  155. FileTxt.WriteLine "<tr><td><a href='" & SubFolder.Path & "'>" & SubFolder.Path & "</a></td><td align=right>" & tSize & "</td><td align=right>" & tfSize & "</td></tr>"
  156. tsize = 0
  157. funcGetSubFolders SubFolder.Path
  158. Next
  159. Set objFldr = Nothing
  160. End Sub
  161.